import asyncio

from mcp_servers.city_server import CityMcpServer


async def main():
    server_obj = CityMcpServer()
    try:
        server = await server_obj.init_mcp_server()
        print("MCP服务器连接成功！ " + server.name)
        # 业务逻辑...
    finally:
        # 假如server_obj.server有close/stop方法，做清理
        if server_obj.server and hasattr(server_obj.server, 'close'):
            print("MCP服务器连接关闭！")
            close_method = server_obj.server.close
            if asyncio.iscoroutinefunction(close_method):
                print("MCP服务器连接关闭-返回True，如果func是一个装饰过的协程函数！")
                await close_method()
            else:
                print("MCP服务器连接关闭！")
                close_method()


if __name__ == "__main__":
    asyncio.run(main())
